# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.shortcuts import render
from .models import UserMessage


# Create your views here.
def get_form(request):



    # 查询
    # all_messages = UserMessage.objects.all()    # 查询所有记录
    all_messages = UserMessage.objects.filter(name=u'胡廷聪', address=u'上海市徐汇区漕溪北路')    # 多条件模糊查询
    # for message in all_messages:
    #     print message.name



    #删除
    # all_messages.delete()


    # 保存数据
    # if request.method == "POST":
    #     name = request.POST.get('name', '') # 取参数名为name的值，如果没有则为空
    #     address = request.POST.get('address', '') # 取参数名为name的值，如果没有则为空
    #     email = request.POST.get('email', '') # 取参数名为name的值，如果没有则为空
    #     object_id = request.POST.get('object_id', '') # 取参数名为name的值，如果没有则为空
    #     message = request.POST.get('message', '') # 取参数名为name的值，如果没有则为空
    #
    #     user_message = UserMessage()
    #     user_message.name = name
    #     user_message.address = address
    #     user_message.email = email
    #     user_message.object_id = u"3"
    #     user_message.message = message
    #     user_message.save()


    #   数据回显
    message = None
    if all_messages:
        message = all_messages[0]
        return render(request, "message_form.html", {
            "my_message": message
        })
    return render(request, "message_form.html")
